package com.cnn.controller;

import anno.CnnInjectService;
import com.cnn.beans.ModelAndView;
import comcnn.service.MyService;
import org.apache.velocity.VelocityContext;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class MyController {

    @CnnInjectService
    private MyService myService;

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");

    public MyService getMyService() {
        return myService;
    }

    public void setMyService(MyService myService) {
        this.myService = myService;
    }



    public String test() throws InterruptedException {

        Thread.sleep(1);
        return String.valueOf(simpleDateFormat.format(System.currentTimeMillis()));
    }

    public String testAnno(){

        return myService.testAnno();
    }

    public ModelAndView testVelo(ModelAndView modelAndView){
        // 设置变量
        VelocityContext ctx = new VelocityContext();
        ctx.put("name", "Velocity");
        List list = new ArrayList();
        list.add("1");
        list.add("2");
        ctx.put("list", list);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("ctx",ctx);
        modelAndView.setMap(map);
        modelAndView.setS("testVelo.vm");
        return  modelAndView;
    }



}
